using System;
using UnityEngine;

namespace Frame
{
    public class ResSvc : MonoBehaviour
    {
        public static ResSvc Instance = null;

        public void InitSvc()
        {
            Instance = this;
        }


        private Action prgCB = null;

        public void AsyncLoadScene(string sceneName, Action loaded)
        {
            GameRoot.Instance.loadingWnd.SetWndState();

            AsyncOperation sceneAsync = SceneManager.LoadSceneAsync(sceneName);
            prgCB = () =>
            {
                float val = sceneAsync.progress;
                GameRoot.Instance.loadingWnd.SetProgress(val);
                if (val == 1)
                {
                    if (loaded != null)
                    {
                        loaded();
                    }

                    prgCB = null;
                    sceneAsync = null;
                    GameRoot.Instance.loadingWnd.SetWndState(false);
                }
            };
        }
    }
}